<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAgentPromotedTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('agent_promoted', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('agent_id')->index()->comment('代理商 ID');
            $table->tinyInteger('level')->comment('代理商(申请晋升时)等级');
            $table->unsignedBigInteger('personal_performance')->comment('(申请晋升时) 个人业绩 (单位 分)');
            $table->unsignedBigInteger('team_performance')->comment('(申请晋升时) 团队业绩 (单位 分)');
            $table->tinyInteger('status')->default(1)->comment('状态: 1.待审核 2.已晋升 3.失败');
            $table->tinyInteger('after_verification_level')->default(0)->comment('代理商(校验后)等级');
            $table->unsignedBigInteger('when_verifying_personal_performance')->default(0)->comment('(校验时) 个人业绩 (单位 分)');
            $table->unsignedBigInteger('when_verifying_team_performance')->default(0)->comment('(校验时) 团队业绩 (单位 分)');

            $table->bigInteger('direct_inviter')->index()->default(0)->comment('(校验时) 用户的直接邀请人');
            $table->bigInteger('indirect_inviter')->index()->default(0)->comment('(校验时) 用户的间接邀请人');
            $table->bigInteger('affiliated_partner')->index()->default(0)->comment('(校验时) 用户的所属合伙人');

            $table->date('check_date')->index()->comment('校验日期 (触发的三天后)');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('agent_promoted');
    }
}
